package com.gdit.zax.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gdit.zax.Constant;
import com.gdit.zax.dao.GroupDao;
import com.gdit.zax.dao.PlanDao;
import com.gdit.zax.entitys.Group;
import com.gdit.zax.entitys.GroupInfoSum;
import com.gdit.zax.entitys.TaskAll;
import com.gdit.zax.factory.DAOFactory;
import com.gdit.zax.utils.DBUtil;
import com.gdit.zax.utils.O;
import com.gdit.zax.utils.TextUtil;
import com.gdit.zax.utils.VeriFicUtil;

public class SearchCalss extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String name = request.getParameter("name");
		int page = TextUtil.String2int(request.getParameter("page"), 1);
		
		//检测连接、用户
		Connection conn = DBUtil.getConnection();
		if (conn==null) {
			O.printFail(response, 1000, "数据库连接失败!");
			return;
		}

		//开始
		DAOFactory dao = DAOFactory.init(conn, request, response);
		
		GroupDao gdap = dao.getGroupDao();
		List<GroupInfoSum>  list = gdap.searchGroup(name,page,10);
		ArrayList<Map<String, Object>> data = new ArrayList<Map<String,Object>>();
		for (GroupInfoSum groupInfoSum : list) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("cid", groupInfoSum.getId());
			map.put("pic",Constant.WEBRoot + groupInfoSum.getPic());
			map.put("name", groupInfoSum.getName());
			map.put("content", groupInfoSum.getContent());
			map.put("sum", groupInfoSum.getSum());
			data.add(map);
		}
		O.printSuccess(response, data);
	
	}

}
